Programming Basics
Outline

Decimal Numbers Review

Digit are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

This is a base 10 numbering system, thus the word decimal

Place positions are one’s, ten’s, hundred’s, thousand’s, etc…

Place values are base on the powers of 10.

The powers of 10 are: 0, 10, 100, 1000, etc… this corresponds to 10^0, 10^1, 10^2, 10^3, etc…

The powers 0, 1, 2, 3, etc… corresponds to the one’s, ten’s, hundred’s, thousand’s, etc… place positions.

Programming Basics: Data Representation

What’s all this business about ones and zeros?

Binary Computers only know two things: One and Zero.

Structure is applied to groups on 1’s and 0’s to gain meaning.

Powers of Two

If you start with 1 penny and double it each day, how much money do you have in 30 days?

If you start with 1 penny and double it each day with a 28% tax rate, how much money do you have in 30 days? ~$40K

Size Unit

Fishing with a bit might get you a nibble or even a byte.

As you tell the story the word gets longer and longer.

Logical Data Type

The world of black and white, true or false

Numeric Data Type

10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 BLAST OFF!

How numbers are stored in a computer

Binary

Two’s company

1’s and 0’s using the power of 2 and grouped in different sizes

Bit Significance

Even bits strive for significance

Right to Left, Least to Most

Bit Positions

Bits are not egalitarian

Bit Position and relation to the power of two

Binary Number Calculations

What gives value to a binary number?

Binary Number Range

There is a lot of range in the digits 1 and 0

Using two digits in three places to get 8 values from 0 to 7

More Binary Number Calculations

What gives value to a binary number? Revisited

A more in-depth binary number calculation

Octal

An eight legged animal

Digits are 0 to 7; base 8

Use % as the notation

Decimal

Finally something we can relate to, what a blessing

Digits are 0 to 9; base 10

Hex

You might think this is a curse

Digits are 0 to 9, A to F; base 16

Use $ as the notation

Conversion

How to change a curse into a blessing

Tables of values

Division remainder method

Binary Addition

Learning how to add all over again

Add 1’s and 0’s with carry

Signed Binary

"Sign, sign, everywhere a sign"

How to represent negative numbers in binary

There is a problem though

One’s & Two’s Complement

Aren’t they so polite

A solution to negative number math, inverse the digits and add 1

Binary Coded Decimal

"What you do that for" – Opie Taylor

A method to code signed floating point decimal numbers in binary only using the decimal digits 0 to 9

Floating Point

Who will rescue this point?

IEEE 754 standard

Character

Programming builds character

ASCII, EBCDIC, Unicode

 

Programming Basics: Constructs

Let’s build something

John von Neumann machine

In some traditions, the father of the modern digital computer

Variable Assignment

Here’s what you do for me

Symbolic representation of a memory location

Holds a value that can be changed

Variable Types

Schizophrenia

Restricted meanings can be placed on variables so that they have a smaller range of values. This aids in writing better programs.

Logical

Let’s be logical about this

Value range is restricted to True or False

Numeric

It’s all in the numbers

Value range is restricted to integer or floating point values

Integer

Easy as 1,2, 3

Whole numbers, no decimal point

Byte

Take a bite

8 bit range

Short

How’s the view down there?

16 bit range

Int

A.K.A. Integer

16 or 32 bit range

Long

Kinda like this lecture

32 or 64 bit range

Floating Point

Still no rescue

Numbers with a decimal point

Different sizes used to conserve memory usage

Float (single)

Trouble

A good range of values

Double

Double trouble

A large range of values

Even Larger Numbers

Will the insanity ever end?

An enormous range of values

Character

There are lots of characters

Single characters or a string of characters

Char

Here is one character

Encoded with some character coding scheme like ASCII

String

Here are a bunch of characters

Very convenient but lots of overhead

Array

A table of values

A complex variable with several components

Name

The variable name of the array

Type

The variable type of the values in the array

Values

Values in the different array slots

Slots

Places in the array where individual values are stored

Index

The extra referencing item besides the variable name to access the different locations where values are stored in the array

Multi-Dimensional Arrays

An array with more than one index to reference the different locations in the array

Constants

Never changes

Proper use is good programming practice

Expressions

Programming is very expressive

Assignment

The left hand learns what the right hand is doing

Arithmetic

Add, Subtract, Multiply, Divide, Modulus, Power

Logical

And, Or, Not, Xor truth tables

Comparison

Equal, Not Equal, Less Than, Greater Than and combinations of such

Precedence

Order of expression evaluation and the use of Parentheses ( )

Bitwise

Binary And, Or, Not, Xor, Left Shift, Right Shift

Conditional/Branching

Making Decisions

If..Then..Else

If (true) Then…

Else (it must be false) …

Select..Case..

Short hand way of doing nested If..Then.Else statements

Branching/Looping

Take a fork in the road

Goto

Unconditional branching

Considered poor programming practice because it violates the one entry point and one exit point of a module as described in structured programming

For..Next

This looping form is to be used when the number of times that the loop should be performed can be pre-determined

While..Loop

This looping form is to be used when a test should be done before the loop should be executed, even the first time. The loop may execute zero (0) to N times, where N may or may not pre-determined

Loop..Until..

This looping form is to be used when a test should be done after the loop has executed at least one time. The loop will execute one (1) to N times, where N may or may not pre-determined

Input/Output

Communicating with the world outside of the program

Read

Write

Open

Close

Subroutines

Method for organizing code, facilitating code reuse

Procedure

Do something but do NOT return a value

Function

Do something and DO return a value

Parameter Passing

Information into the subroutine

Call by value

Call by reference

Return Values

Function return value, explicitly or implicitly assigned